//1.哈希表 - 存在重复元素
class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        unordered_map<int, int> hash;
        for(auto x : nums)
        {
            if(hash.count(x)) return true;
            hash[x]++;
        }
        return false;
    }
};

//2.哈希表 - 存在重复元素II
class Solution {
public:
    bool containsNearbyDuplicate(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        for(int i = 0; i < nums.size(); i++)
        {
            int x = nums[i];
            if(hash.count(x) && abs(hash[x] - i) <= k) return true;
            hash[x] = i;    
        }
        return false;
    }
};